pub mod lexer;
pub mod parser;

mod test;
pub mod ops;

use std::{borrow::Borrow, result};

pub use lexer::Lexer;
pub use parser::Parser;

use crate::Expr;

pub type Result<T> = result::Result<T, Error>;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error(transparent)]
    Lex(#[from] lexer::Error),
    #[error(transparent)]
    Parse(#[from] parser::Error),
    #[error("User custom: {0}")]
    Custom(String),
}

pub fn parse<S: Borrow<str>>(src: S) -> Result<Expr> {
    Parser::new(src.borrow()).parse()
}

pub fn parse_exprs(src: &str) -> Result<Vec<Expr>> {
    Parser::new(src).parse_exprs()
}